package com.shanzmoo.db.sys.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.shanzmoo.db.sys.entity.RoleMenuEntity;
import com.shanzmoo.db.sys.mapper.RoleMenuMapper;
import com.shanzmoo.db.sys.service.IRoleMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Gzhao
 * @since 2020-11-16
 */
@Service
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenuEntity> implements IRoleMenuService {

    @Override
    public void saveRoleMenuIds(Integer roleId, List<Integer> menuIds) {
        baseMapper.deleteByRoleId(roleId);

        if (CollectionUtil.isEmpty(menuIds)) {
            return;
        }
        List<RoleMenuEntity> roleMenuEntityList = menuIds.stream().map(menuId -> {
            return new RoleMenuEntity(roleId, menuId);
        }).collect(Collectors.toList());
        baseMapper.insertBatch(roleMenuEntityList);

    }
}
